package com.ruoyi.yuce.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.yuce.domain.pojo.CoChangZhan;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yuce.domain.Changzhan;
import com.ruoyi.yuce.service.IChangzhanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 场站Controller
 *
 * @author ruoyi
 * @date 2023-01-17
 */
@RestController
@RequestMapping("/ruoyi-yuce/changzhan")
@DataSource(value = DataSourceType.SLAVE)
public class ChangzhanController extends BaseController
{
    @Autowired
    private IChangzhanService changzhanService;

    /**
     * 查询场站列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:changzhan:list')")
    @GetMapping("/list")
    public TableDataInfo list(Changzhan changzhan)
    {
        startPage();
        List<Changzhan> list = changzhanService.selectChangzhanList(changzhan);
        return getDataTable(list);
    }


    /**
     * 导出场站列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:changzhan:export')")
    @Log(title = "场站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Changzhan changzhan)
    {
        List<Changzhan> list = changzhanService.selectChangzhanList(changzhan);
        ExcelUtil<Changzhan> util = new ExcelUtil<Changzhan>(Changzhan.class);
        util.exportExcel(response, list, "场站数据");
    }

    /**
     * 获取场站详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:changzhan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(changzhanService.selectChangzhanById(id));
    }

    /**
     * 新增场站
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:changzhan:add')")
    @Log(title = "场站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Changzhan changzhan)
    {
        return toAjax(changzhanService.insertChangzhan(changzhan));
    }

    /**
     * 修改场站
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:changzhan:edit')")
    @Log(title = "场站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Changzhan changzhan)
    {
        return toAjax(changzhanService.updateChangzhan(changzhan));
    }

    /**
     * 删除场站
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:changzhan:remove')")
    @Log(title = "场站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(changzhanService.deleteChangzhanByIds(ids));
    }

}
